package com.hmy.infrastructure.controller;

import com.hmy.ccp.common.result.JsonResult;
import com.hmy.ccp.error.annotations.HmyGateWayController;
import com.hmy.infrastructure.api.bo.response.oss.OssCredentialsResponse;
import com.hmy.infrastructure.api.bo.response.oss.OssSignatureResponse;
import com.hmy.infrastructure.bo.request.OssStoreDirRequest;
import com.hmy.infrastructure.bo.response.OssStoreDirResponse;
import com.hmy.infrastructure.service.oss.OssStsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "OSS管理")
@Validated
@RestController
@Slf4j
@HmyGateWayController
public class OssController {

    private final OssStsService ossStsService;

    public OssController(OssStsService ossStsService) {
        this.ossStsService = ossStsService;
    }


    @GetMapping("/api/oss/signature")
    public JsonResult<OssSignatureResponse> getSignature(@RequestParam(required = true) String dir) {

        return JsonResult.success(ossStsService.getOssSignature(dir));

    }

    @GetMapping("/api/oss/credentials")
    public JsonResult<OssCredentialsResponse> getCredentials(){
        return JsonResult.success(ossStsService.getCredentials());
    }

    @GetMapping("/api/oss/store-dir")
    public JsonResult<OssStoreDirResponse> storeDir(OssStoreDirRequest storeDirRequest){
        return JsonResult.success(this.ossStsService.getOssStoreDir(storeDirRequest));
    }
}